<!--银行卡列表-->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
      <el-form-item :label="$t('video.list.whether-to-review')" prop="status">
        <el-select v-model="queryParams.type" clearable placeholder="请选择">
          <el-option
              v-for="item in typeList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button type="primary" plain size="mini" @click="open = true;form={}" v-hasPermi="['video:list:add']">新 增</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="权限名" align="center" prop="limitName" width="180" show-overflow-tooltip/>
      <el-table-column label="相对路径" align="center" prop="uri" width="240" show-overflow-tooltip />
      <el-table-column label="类型" align="center" prop="type" width="180" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.type == 1">用户行为</el-tag>
          <el-tag type="warning" v-if="scope.row.type == 2">店铺行为</el-tag>
          <el-tag type="info" v-if="scope.row.type == 3">主播行为</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="type" width="180" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <el-switch
              v-model="scope.row.status"
              :active-value="0"
              :inactive-value="1"
              active-color="#13ce66"
              inactive-color="#ff4949"
              @change="disableChange(scope.row)">
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180"
                       :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{ scope.row.updateTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" min-width="150px">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit"
                     @click="updateStore(scope.row)">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList" />
    <!-- 添加或修改店铺等级对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body @close="$refs['form'].resetFields()">
      <el-form ref="form" :model="form" :rules="Rules" label-width="110px" label-position="left">
        <el-form-item label="权限名" prop="limitName">
          <el-input type="text" class="modal-input" v-model="form.limitName" placeholder="请输入权限名" />
        </el-form-item>
        <el-form-item label="相对路径" prop="uri">
          <el-input class="modal-input" v-model="form.uri" placeholder="请输入相对路径" />
        </el-form-item>
        <el-form-item :label="$t('video.list.whether-to-review')" prop="type">
          <el-select v-model="form.type" clearable placeholder="请选择类型">
            <el-option
                v-for="item in typeList"
                :key="item.value"
                :label="item.label"
                :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleChange">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import RemoteSelect from '@/components/RemoteSelect/index.vue'
import { limitDelete, limitList, addOrUpdate, limitShelves } from '@/api/system/jurisdiction'
import { freezeUser } from '@/api/user/list'
import { addList } from '@/api/activity/seckill'

export default {
  name: "bankCardList",
  components: { RemoteSelect },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 用户完成线下理财信息表格数据
      dataList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      bankList:[],
      typeList: [{
        label: '用户行为',
        value: 1
      }, {
        label: '店铺行为',
        value: 2
      }, {
        label: '主播行为',
        value: 3
      }],
      open:false,
      form:{},
      title:'',
      // 表单校验
      Rules: {
        limitName: { required: true, message: '权限名不能为空', trigger: 'blur' },
        uri: { required: true, message: '相对路径不能为空', trigger: 'blur' },
        type: { required: true, message: '选择类型不能为空', trigger: 'blur' },
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleChange(){
      this.$refs['form'].validate(valid => {
        console.log(this.form)
        if (valid) {
          addOrUpdate(this.form).then(res => {
            this.open = false;
            this.getList()
          })
        }
      })
    },
    cancel(){
      this.form = {};
      this.open = false;
    },
    /** 查询用户完成线下理财信息列表 */
    getList() {
      this.loading = true;
      limitList(this.queryParams).then(response => {
        this.dataList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 修改按钮操作 */
    updateStore(row) {
      this.open = true;
      this.form = JSON.parse(JSON.stringify(row))
    },
    /* 修改状态 */
    disableChange: function(row) {
      limitShelves(row.id).then(() => {
        this.getList()
        this.$modal.msgSuccess('修改成功')
      }).catch()
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
      this.$modal.confirm('是否确认删除该权限配置项？').then(function () {
        return limitDelete([id]);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
  }
};
</script>
